package cumt.kydd.authoringplatform.mapper;

import cumt.kydd.authoringplatform.bean.History;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface HistoryMapper {
    @Insert("INSERT INTO user_history (name,password,originText,title,summary)  VALUES(#{name}, #{password}, #{originText} ,#{title} ,#{summary})")
    int insertHistory(History history);

    @Select("SELECT historyID,name,password,originText,title,summary,isDelete,isFavor From user_history WHERE historyID=#{historyID}")
    History selectHistoryByID(@Param("historyID")Integer ID);

    @Select("SELECT historyID From user_history WHERE name=#{name} AND isDelete=0")
    List<Integer> selectHistoryIDByNameAndIsDelete(@Param("name")String name);

    @Update("Update user_history SET isDelete=#{isDelete} WHERE historyID=#{historyID}")
    int updateIsDelete(@Param("isDelete") int isDelete, @Param("historyID")Integer historyID);

    @Select("SELECT historyID,name,password,originText,title,summary,isDelete From user_history WHERE historyID=#{historyID} AND isDelete=0")
    History selectHistoryByIDAndIsDelete(@Param("historyID")Integer ID);

    @Select("SELECT historyID From user_history WHERE name=#{name} AND isDelete=1")
    List<Integer> selectHistoryIDByNameAndIsDeleteYet(@Param("name")String name);

    @Select("SELECT historyID,name,password,originText,title,summary,isDelete From user_history WHERE historyID=#{historyID} AND isDelete=1")
    History selectHistoryByIDAndIsDeleteYet(@Param("historyID")Integer ID);

    @Update("Update user_history SET isFavor=#{isFavor} WHERE historyID=#{historyID}")
    int updateIsFavor(@Param("isFavor") int isFavor, @Param("historyID")Integer historyID);

    @Select("SELECT historyID From user_history WHERE name=#{name} AND isDelete=0 AND isFavor=1")
    List<Integer> selectHistoryIDByNameAndIsFavor(@Param("name")String name);

    @Select("SELECT historyID,name,password,originText,title,summary,isDelete,isFavor From user_history WHERE historyID=#{historyID} AND isDelete=0 AND isFavor=1")
    History selectHistoryByIDAndIsFavor(@Param("historyID")Integer ID);

}
